home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Server⁄Tracker 4.0 / extern.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-01  |  15.0 KB  |  536 lines  |  [TEXT/KAHL]

  1. /* extern.h */
  2.  
  3. /* $Id: extern.h,v 4.0 1994/01/11 17:46:25 espie Exp espie $
  4.  * $Log: extern.h,v $
  5.  * Revision 4.0  1994/01/11  17:46:25  espie
  6.  * Lots of new proto for all functions.
  7.  *
  8.  * Revision 1.10  1994/01/09  17:36:22  Espie
  9.  * Generalized open.c.
  10.  *
  11.  * Revision 1.9  1994/01/09  04:50:56  Espie
  12.  * Comments.
  13.  *
  14.  * Revision 1.8  1994/01/08  19:43:57  Espie
  15.  * Added checkbrk.
  16.  *
  17.  * Revision 1.7  1994/01/08  03:55:43  Espie
  18.  * General cleanup.
  19.  *
  20.  * Revision 1.6  1994/01/06  22:32:42  Espie
  21.  * Suppressed some unused code.
  22.  *
  23.  * Revision 1.5  1994/01/05  13:53:25  Espie
  24.  * Better portability.
  25.  *
  26.  * Revision 1.4  1993/12/28  13:54:44  Espie
  27.  * Removed init_display.
  28.  * No more reentrency problems with INIT_ONCE.
  29.  * Protos for ui: notice, info, scroller, pattern display.
  30.  *
  31.  * Revision 1.3  1993/12/26  22:48:18  Espie
  32.  * Mostly working.
  33.  * Just dies with a guru.
  34.  * Plus timing problems at start.
  35.  *
  36.  * Revision 1.2  1993/12/26  18:54:21  Espie
  37.  * New prototypes.
  38.  *
  39.  * Revision 1.1  1993/12/26  00:55:53  Espie
  40.  * Initial revision
  41.  *
  42.  * Revision 3.15  1993/12/04  16:12:50  espie
  43.  * Added prototypes.
  44.  *
  45.  * Revision 3.14  1993/12/02  15:45:33  espie
  46.  * Added some protos.
  47.  *
  48.  * Revision 3.13  1993/11/17  15:31:16  espie
  49.  * *** empty log message ***
  50.  *
  51.  * Revision 3.12  1993/11/11  20:00:03  espie
  52.  * Amiga support.
  53.  *
  54.  * Revision 3.10  1993/07/18  10:39:44  espie
  55.  * Added pid, fork, show.
  56.  *
  57.  * Revision 3.8  1993/01/15  14:00:28  espie
  58.  * Added bg/fg test.
  59.  *
  60.  * Revision 3.7  1992/12/03  15:00:50  espie
  61.  * stty_sane.
  62.  *
  63.  * Revision 3.5  1992/11/24  10:51:19  espie
  64.  * New audio functions.
  65.  *
  66.  * Revision 3.2  1992/11/22  17:20:01  espie
  67.  * Simplified delay_pattern.
  68.  *
  69.  * Revision 3.1  1992/11/19  20:44:47  espie
  70.  * Protracker commands.
  71.  *
  72.  * Revision 3.0  1992/11/18  16:08:05  espie
  73.  * New release.
  74.  *
  75.  * Revision 2.19  1992/11/17  17:06:25  espie
  76.  * Lots of new functions to account for new interface.
  77.  * open_file support.
  78.  * Separated mix/stereo stuff.
  79.  * Added possibility to get back to MONO for the sgi.
  80.  * Added stereo capabilities to the indigo version.
  81.  * Added some new song types to automatize the choice process.
  82.  * Moved resampling to audio, added prototype.
  83.  * Added SAMPLE_FAULT, for trying to play
  84.  * a note without a sample (not really an error).
  85.  *
  86.  * Revision 1.7  1991/11/08  14:25:55  espie
  87.  * Modified audio prototype so that you can change
  88.  * frequency.
  89.  * Added prototype for release_song.
  90.  * Added arpeggio effect.
  91.  * Added entries for new effects.
  92.  * Added entries for commands.c.
  93.  */
  94.  
  95.  
  96.  
  97. /* audio.c */
  98. #define ACCURACY 12
  99. #define fix_to_int(x) ((x) >> ACCURACY)
  100. #define int_to_fix(x) ((x) << ACCURACY)
  101.  
  102.  
  103. /* release_audio_channels:
  104.  * free every audio channel previously allocated
  105.  */
  106. XT void release_audio_channels P((void));
  107.  
  108. /* chan = new_channel_tag_list(prop):
  109.  * allocates a new channel for the current song
  110.  * No properties are currently defined.
  111.  */
  112. XT struct audio_channel *new_channel_tag_list P((struct tag *prop));
  113.  
  114. /* init_tables(oversample, frequency):
  115.  * precomputes the step_table and the pitch_table
  116.  * according to the desired oversample and frequency.
  117.  * This is static, you can call it again whenever you want.
  118.  * Adjust the currently used audio channels if needed.
  119.  */
  120. XT void init_tables P((int oversample, int frequency));
  121.  
  122. /* resample(oversample, number):
  123.  * send number samples out computed according
  124.  * to the current state of channels
  125.  * and oversample.
  126.  */
  127. XT void resample P((int oversample, int number));
  128.  
  129. /* play_note(au, samp, pitch)
  130.  * set audio channel au to play samp at pitch
  131.  */
  132. XT void play_note P((struct audio_channel *au, struct sample_info *samp, \
  133. int pitch));
  134.  
  135. /* set_play_pitch(au, pitch):
  136.  * set channel au to play at pitch pitch
  137.  */
  138. XT void set_play_pitch P((struct audio_channel *au, int pitch));
  139.  
  140. /* set_play_volume(au, volume):
  141.  * set channel au to play at volume volume
  142.  */
  143. XT void set_play_volume P((struct audio_channel *au, int volume));
  144.  
  145. /* set_play_position(au, pos):
  146.  * set position in sample for channel au at given offset
  147.  */
  148. XT void set_play_position P((struct audio_channel *au, int pos));
  149.  
  150.  
  151. /* automaton.c */
  152. /* init_automaton(a, song, start):
  153.  * put the automaton a in the right state to play song from pattern start.
  154.  */
  155. XT void init_automaton P((struct automaton *a, struct song *song, int start));
  156.  
  157. /* next_tick(a):
  158.  * set up everything for the next tick.
  159.  */
  160. XT void next_tick P((struct automaton *a));
  161.  
  162.  
  163. /* commands.c */
  164. /* init_effects(): sets up all data for the effects */
  165. /* (not set up as auto_init due to huge overhead) */
  166. XT void init_effects P((void (*table[])()));
  167.  
  168. /* do_nothing: this is the default behavior for an effect.
  169.  */
  170. XT void do_nothing P((struct channel *ch));
  171.  
  172.  
  173. /* dump_song.c */
  174. /* dump_song(s): 
  175.  * displays some information pertinent to the given 
  176.  * song s.
  177.  */
  178. XT void dump_song P((struct song *song));
  179.  
  180.  
  181. /* display.c */
  182.  
  183. /* dump_event(ch, e): dump event e as occuring on channel ch
  184.  */
  185. XT void dump_event P((struct channel *ch, struct event *e));
  186.  
  187.  
  188. /* main.c */
  189.  
  190. #define OLD 0
  191. #define NEW 1
  192. /* special new type: for when we try to read it as both types.
  193.  */
  194. #define BOTH 2
  195. /* special type: does not check the signature */
  196. #define NEW_NO_CHECK 3
  197.  
  198.  
  199. /* error types. Everything is centralized,
  200.  * and we check in some places (see st_read, player and main)
  201.  * that there was no error. Additionnally signal traps work
  202.  * that way too.
  203.  */
  204.  
  205. /* normal state */
  206. #define NONE 0  
  207. /* read error */
  208. #define FILE_TOO_SHORT 1
  209. #define CORRUPT_FILE 2
  210. /* trap error: goto next song right now */
  211. #define NEXT_SONG 3
  212. /* run time problem */
  213. #define FAULT 4
  214. /* the song has ended */
  215. #define ENDED 5
  216. /* unrecoverable problem: typically, trying to 
  217.  * jump to nowhere land.
  218.  */
  219. #define UNRECOVERABLE 6
  220. /* Missing sample. Very common error, not too serious. */
  221. #define SAMPLE_FAULT 7
  222. /* New */
  223. #define PREVIOUS_SONG 8
  224. #define OUT_OF_MEM 9
  225. XT int error;
  226.  
  227. /* notes.c */
  228. #define NUMBER_NOTES 120
  229. #define NUMBER_FINETUNES 17
  230. XT short pitch_table[NUMBER_NOTES][NUMBER_FINETUNES];    /* 120 * 17 = big ! */
  231.  
  232. /* note = find_note(pitch):
  233.  * find note corresponding to a given pitch. 
  234.  */
  235. XT int find_note P((int pitch));
  236.  
  237. /* oldtranspose = transpose_song(song, newtranspose):
  238.  * tranpose song to a new pitch
  239.  */
  240. XT int transpose_song P((struct song *song, int newtranspose));
  241.  
  242. /* name = name_of_note(note):
  243.  * name of the note. Warning! This name is only valid
  244.  * until a new call to name_of_note.
  245.  */
  246. XT char *name_of_note P((int note));
  247.  
  248.  
  249.  
  250.  
  251.  
  252. /* open.c */
  253. /* handle = open_file(filename, mode, path):
  254.  * transparently open a compressed file.
  255.  */
  256. XT struct exfile *open_file P((char *fname, char *fmode, char *path));
  257.  
  258. /* handle = file_handle(f):
  259.  * obtain the actual FILE handle from the private structure
  260.  */
  261. XT FILE *file_handle P((struct exfile *f));
  262.  
  263. /* close_file(handle):
  264.  * close a file that was opened with open_file.
  265.  */
  266. XT void close_file P((struct exfile *file));
  267.  
  268. XT int getc_file P((struct exfile *file));
  269. XT int tell_file P((struct exfile *file));
  270.  
  271.  
  272.  
  273.  
  274. /* player.c */
  275.  
  276. /* reset_note(ch, note, pitch):
  277.  * set channel ch to play note at pitch pitch
  278.  */
  279. XT void reset_note P((struct channel *ch, int note, int pitch));
  280.  
  281. /* set_current_pitch(ch, pitch):
  282.  * set ch to play at pitch pitch
  283.  */
  284. XT void set_current_pitch P((struct channel *ch, int pitch));
  285.  
  286. /* set_current_volume(ch, volume):
  287.  * set channel ch to play at volume volume
  288.  */
  289. XT void set_current_volume P((struct channel *ch, int volume));
  290.  
  291. /* set_position(ch, pos):
  292.  * set position in sample for current channel at given offset
  293.  */
  294. XT void set_position P((struct channel *ch, int pos));
  295.  
  296. /* init_player(oversample, frequency):
  297.  * sets up the player for a given oversample and
  298.  * output frequency.
  299.  * Note: we can call init_player again to change oversample and
  300.  * frequency.
  301.  */
  302. XT void init_player P((int o, int f));
  303.  
  304. /* play_song(song, start):
  305.  * play the song.
  306.  */
  307. XT struct tag *play_song P((struct song *song, int start));
  308. /* returns tags as shown further down in get_ui */
  309.  
  310.  
  311.  
  312. /* st_read.c */
  313. /* s = read_song(f, type):
  314.  * tries to read f as a song of type NEW/OLD.
  315.  * returns NULL (and an error) if it doesn't work.
  316.  * Returns a dynamic song structure if successful.
  317.  */
  318. XT struct song *read_song P((struct exfile *f, int type));
  319.  
  320. /* release_song(s):
  321.  * release all the memory song occupies.
  322.  */
  323. XT void release_song P((struct song *song));
  324.  
  325.  
  326.  
  327. /* setup_audio.c */
  328. /* setup_audio(ask_freq, stereo, oversample):
  329.  * setup the audio output with these values 
  330.  */
  331. XT void setup_audio P((int f, boolean s, int o));
  332. /* do_close_audio():
  333.  * close audio only if needed
  334.  */
  335. XT void do_close_audio P((void));
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343. /* xxx_audio.c */
  344. /* frequency = open_audio(f, s):
  345.  * try to open audio with a sampling rate of f, and eventually stereo.
  346.  * We get the real frequency back. If we ask for 0, we
  347.  * get the ``preferred'' frequency.
  348.  * Note: we have to close_audio() before we can open_audio() again.
  349.  * Note: even if we don't ask for stereo, we still have to give a
  350.  * right and left sample.
  351.  */
  352. XT int open_audio P((int f, int s));
  353. /* close_audio():
  354.  * returns the audio to the system control, doing necessary
  355.  * cleanup
  356.  */
  357. XT void close_audio P((void));
  358. /* set_mix(percent): set mix channels level.
  359.  * 0: spatial stereo. 100: mono.
  360.  */
  361. XT void set_mix P((int percent));
  362.  
  363. /* output_samples(l, r): outputs a pair of stereo samples.
  364.  * Samples are 15 bits signed.
  365.  */
  366. XT void output_samples P((int left, int right));
  367.  
  368. /* flush_buffer(): call from time to time, because buffering
  369.  * is done by the program to get better (?) performance.
  370.  */
  371. XT void flush_buffer P((void));
  372.  
  373. /* discard_buffer(): try to get rid of the buffer contents
  374.  */
  375. XT void discard_buffer P((void));
  376.  
  377. /* new_freq = update_frequency():
  378.  * if !0, frequency changed and playing should be updated accordingly
  379.  */
  380. XT int update_frequency P((void));
  381.  
  382. /* set_synchro(boolean):
  383.  * try to synchronize audio output by using a smaller buffer
  384.  */
  385. XT void set_synchro P((boolean s));
  386.  
  387. #ifdef SPECIAL_SAMPLE_MEMORY
  388. XT GENERIC alloc_sample P((int len));
  389. XT void free_sample P((GENERIC s));
  390. XT int obtain_sample P((GENERIC start, int l, FILE *f));
  391.  
  392. #else
  393. #define alloc_sample(len)        calloc(len, 1)
  394. #define free_sample(sample)        free(sample)
  395. #define obtain_sample(start, l, f)    fread(start, 1, l, f)
  396. #endif
  397.  
  398.  
  399.  
  400. /* tools.c */
  401. /* v = read_env(name, default):
  402.  * read a scalar value in the environment
  403.  */
  404. XT int read_env P((char *name, int def));
  405.  
  406.  
  407.  
  408.  
  409. /* autoinit.c */
  410. /* used for decentralizing initialization/termination of various
  411.  * system routines
  412.  */
  413.  
  414. /* end_all(s): the program must exit now, after displaying s to the user, usually 
  415.  * through notice and calling all stacked at_end() functions. s may be 0 for normal
  416.  * exit. DO NOT use exit() anywhere in tracker but end_all() instead.
  417.  */
  418. XT void end_all P((char *s));
  419.  
  420. /* at_end(cleanup): stack cleanup to be called at program's termination
  421.  */
  422. XT void at_end P((void (*cleanup)(void)));
  423.  
  424. /* INIT_ONCE: macro for autoinitialization of routines.
  425.  * modules that need an init routine should LOCAL void INIT = init_routine,
  426.  * and add INIT_ONCE; at EVERY possible first entry point for their routine.
  427.  * (I mean every, don't try to second-guess me !)
  428.  */
  429. #define INIT_ONCE        if (INIT)    {void (*func)P((void)) = INIT; INIT = 0; (*func)();}
  430.  
  431.  
  432. /* $(UI)/ui.c */
  433. /* see unix/ui.c for the general unix implementation.
  434.  * The old may_getchar() has been replaced by the tag-based
  435.  * get_ui
  436.  */
  437. /* get_ui(): returns an array of tags that reflect the current user-interface
  438.  * actions. Unknown tags WILL be ignored.
  439.  * Note that get_ui will be called about once every tick, providing a poor man's
  440.  * timer to the interface writer if needed to code multiple actions on the same
  441.  * user-input. See unix/termio.c for a good example.
  442.  * see amiga/ui.c for the correct way to do it when you have a real timer.
  443.  *
  444.  * VERY IMPORTANT: who do the tags belong to ?
  445.  *    as a general rule, result (and their values) MUST only be considered
  446.  *    valid between two calls to get_ui ! Be careful to call get_ui ONLY at
  447.  *    reasonable places.
  448.  *    One exception: structures that are dynamically allocated (like UI_LOAD_SONG
  449.  *    values) will ONLY get freed when you ask for it !
  450.  */
  451. XT struct tag *get_ui P((void));
  452. #define BASE_UI 10
  453. #define UI_NEXT_SONG    (BASE_UI)            /* load next song */
  454. #define UI_PREVIOUS_SONG (BASE_UI + 1)    /* load previous song */
  455. #define UI_LOAD_SONG (BASE_UI + 2)        /* load song. Name as value */
  456. #define UI_SET_BPM (BASE_UI + 3)          /* set beat per minute to value */
  457. #define UI_JUMP_TO_PATTERN (BASE_UI + 4)  /* jump to pattern #value. Use display_pattern to
  458.                                            * keep in sync with the player
  459.                                            */
  460. #define UI_RESTART (BASE_UI + 5)          /* restart current song. Not quite jump to 0 */
  461. #define UI_QUIT (BASE_UI + 6)             /* need I say more ? */
  462. #define UI_DISPLAY (BASE_UI + 7)          /* status of scrolling window: true or false */
  463.  
  464.  
  465. /* player.c translates the get_ui() tags in a standard way.
  466.  * Actually it doesn't translate anything right now...
  467.  */
  468. #define BASE_PLAY 20
  469. #define PLAY_NEXT_SONG UI_NEXT_SONG
  470. #define PLAY_PREVIOUS_SONG UI_PREVIOUS_SONG
  471. #define PLAY_LOAD_SONG UI_LOAD_SONG
  472.  
  473. #define PLAY_ERROR BASE_PLAY
  474.  
  475. /* Most of these functions are information display function.
  476.  * A correct implementation should heed run_in_fg() if needed
  477.  */
  478.  
  479. /* notice(s): important message for the user (terminal error maybe).
  480.  * take extra pain to make it apparent even if run in background
  481.  */
  482. XT void notice P((char *s));
  483.  
  484. /* status(s): some indication of the system current status... 
  485.  * Used for fleeing error messages too. 
  486.  * s = 0 is valid and indicates return to the default status.
  487.  */
  488. XT void status P((char *s));
  489.  
  490. /* begin_info: open a logical information window.
  491.  * returns 0 if the window couldn't be opened.
  492.  * A NULL window shouldn't be used, but don't count on it !
  493.  */
  494. XT GENERIC begin_info P((char *title));
  495. /* info(handle, line): add a line to the info window,
  496.  * completing the current line if applicable
  497.  */
  498. XT void info P((GENERIC handle, char *line));
  499. /* infos(handle, line): add to the current line of the info window
  500.  */
  501. XT void infos P((GENERIC handle, char *s));
  502. /* end_info(handle): this window is complete...
  503.  */
  504. XT void end_info P((GENERIC handle));
  505.  
  506. /* Scrolling score display:
  507.  * new_scroll() returns a writable buffer of 4*14-1 characters in
  508.  * which the program (usually display.c) will write what it wills.
  509.  * It can return 0 if not applicable.
  510.  */
  511. XT char *new_scroll P((void));
  512.  
  513. /* scroll: returns this scrolling line to the program. Note that
  514.  * scroll doesn't take any argument, and implies calls to new_scroll/scroll
  515.  * are paired. After a call to scroll, the last pointer returned by new_scroll
  516.  * should be considered invalid !
  517.  */
  518. XT void scroll P((void));
  519.  
  520. /* display_pattern(current, total): we are at current/total in the current song
  521.  * may be used as a poor man's timer.
  522.  */
  523. XT void display_pattern P((int current, int total));
  524.  
  525. /* song_title(s): the current song title is s.
  526.  * ui implementors: Don't count on this pointer remaining valid AFTER the call,
  527.  * make a copy if needed
  528.  */
  529. XT void song_title P((char *s));
  530.  
  531. /* boolean checkbrk():
  532.  * check whether a break occured and we should end right now.
  533.  * Call it often enough (like when loading songs and stuff)
  534.  */
  535. XT boolean checkbrk P((void));
  536.